﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LAVAA.DAL;

namespace TestLavaa
{
    [TestClass]
    public class DataLoader
    {
        [TestMethod]
        public void AddBaseData()
        {
            LavaaEntitiesConnection _context = new LavaaEntitiesConnection();

            ActivityType ga = new ActivityType()
            {
                Id = Guid.NewGuid(),
                Name = "Gå"
            };

            ActivityType lopa = new ActivityType()
            {
                Id = Guid.NewGuid(),
                Name = "Löpa"
            };

            ActivityType vanka = new ActivityType()
            {
                Id = Guid.NewGuid(),
                Name = "Vanka"
            };

            _context.ActivityTypes.Add(ga);
            _context.ActivityTypes.Add(lopa);
            _context.ActivityTypes.Add(vanka);


            RewardType rewardType = new RewardType()
            {
                Id = Guid.NewGuid(),
                Name = "Vantar",
                IsCurrentlyUsable = true,
                RequiredNrOfPoints = 100,
                Description = "Fiina vantar!",
            };
            _context.RewardTypes.Add(rewardType);


            UserGroup group = new UserGroup()
            {
                Id = Guid.NewGuid(),
                Name = "Default"
            };


            User user = new User()
            {
                Id = Guid.NewGuid(),
                FirstName = "Andreas",
                LastName = "Gustafsson",
                UserId = "andreas@lavaa.com",
                UserGroup = group,
            };

            _context.Users.Add(user);

            _context.SaveChanges();
        }

        [TestMethod]
        public void DeleteBaseData()
        {
            LavaaEntitiesConnection _context = new LavaaEntitiesConnection();

            foreach (var activity in _context.Activities.ToArray())
            {
                _context.Activities.Remove(activity);
            }

            foreach (var user in _context.Users.ToArray())
            {
                _context.Users.Remove(user);
            }

            foreach (var userGroup in _context.UserGroups.ToArray())
            {
                _context.UserGroups.Remove(userGroup);
            }

            foreach (var rewardType in _context.RewardTypes.ToArray())
            {
                _context.RewardTypes.Remove(rewardType);
            }

            foreach (var activityType in _context.ActivityTypes.ToArray())
            {
                _context.ActivityTypes.Remove(activityType);
            }

            _context.SaveChanges();
        }
    }
}
